package models

import (
	"gorm.io/gorm"
)

type Shopwindow struct {
	gorm.Model
	Name                 string  `gorm:"type:varchar(20);comment:'橱窗名字'"`
	Stock                int     `gorm:"type:int;comment:'库存'"`
	Price                float64 `gorm:"type:decimal(10,2);comment:'橱窗的价格'"`
	UserId               int     `gorm:"type:int;comment:'用户ID'"`
	ShopwindowCargetryId int     `gorm:"type:int;comment:'分类id'"`
	Image                string  `gorm:"type:varchar(255);comment:'商品橱窗图片'"`
	Status               int     `gorm:"type:int;comment:'商品状态 0 已下架 1 上架'"`
}
type Shop struct {
	gorm.Model
	Name                 string  `gorm:"type:varchar(20);comment:'商品名字'"`
	Num                  string  `gorm:"type:char(32);comment:'商品销量'"`
	Price                float64 `gorm:"type:decimal(10,2);comment:'商品的价格'"`
	Status               int     `gorm:"type:int;comment:'商品状态 0 已下架 1 上架'"`
	UserId               int     `gorm:"type:int;comment:'用户ID'"`
	ShopwindowCargetryId int     `gorm:"type:int;comment:'分类id'"`
	Image                string  `gorm:"type:varchar(255);comment:'商品图片'"`
}
type ShopwindowCargetry struct {
	gorm.Model
	Caregoryname string `gorm:"type:varchar(20);comment:'橱窗分类名字'"`
	ShopwindowId int    `gorm:"type:int;comment:'橱窗分类id'"`
}

func (s *Shopwindow) CreateShop(db *gorm.DB) error {
	err := db.Create(&s).Error
	return err
}

func (s *Shopwindow) Findshop(db *gorm.DB, id int) error {
	err := db.Model(Shopwindow{}).Where("id =?", id).Limit(1).Find(&s).Error
	return err
}

func (s *Shopwindow) Update(db *gorm.DB, id int, Status int) error {
	err := db.Model(Shopwindow{}).Where("id =?", id).Updates(map[string]interface{}{
		"status": Status,
	}).Error
	return err
}

func (sc *ShopwindowCargetry) CreateShop(db *gorm.DB) error {
	err := db.Create(&sc).Error
	return err
}

func (se *Shop) CreateShop(db *gorm.DB) error {
	err := db.Create(&se).Error
	return err
}
func (s *ShopwindowCargetry) Findshop(db *gorm.DB, Caregoryname string) error {
	err := db.Model(Shopwindow{}).Where("_caregoryname =?", Caregoryname).Limit(1).Find(&s).Error
	return err
}

//
//func (ss *Shop) UpdateShop(db *gorm.DB, id int) error {
//	 err:=db.Model(Shop{}).Where("id =?", id).Updates(ss.Num).Count("num+1")
//	 return err
//}
